const jwt = require('jsonwebtoken');
const privateKey = 'sun'

module.exports = {
    Validata(reuls, body) {
        //定制化校验所有参数类型校验，防止恶意传参
        return this.app.validator.validate(reuls, body);
    },
    token: {
        //生成token
        sign(userObj) {
            return jwt.sign(userObj, privateKey);
        },
        //解密token
        verify(userToken) {
            return new Promise((resovle, reject) => {
                jwt.verify(userToken, privateKey, (err, decoded)=>{
                    if(err){
                        reject(err)
                    }else{
                        resovle(decoded)
                    }
                });
            })
        }
    }
}